﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using QNote.Model;
using QNote.Services;

namespace QNote.ViewModel
{
    internal class MainViewModel: ObservableObject
    {
        public Note Note { get; private set; }

        public RelayCommand ClearCommand { get; private set; }

        private ISerializationService service;

        public MainViewModel(ISerializationService service)
        {
            this.service = service;
            Note = service.Deserialize() ?? new Note(string.Empty);
            ClearCommand = new RelayCommand(DoClear);
        }

        public void SaveNote()
        {
            service.Serialize(Note);
        }

        private void DoClear()
        {
            Note.Text = string.Empty;
            OnPropertyChanged(nameof(Note));
        }
    }
}
